package com.cytech.cloudclinic.utils;

import android.content.Context;

import com.cytech.cloudclinic.base.BaseObserver;
import com.cytech.cloudclinic.http.API;
import com.cytech.cloudclinic.http.RetrofitService;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;

public class RequestWithViewUtils {
    public API.WAZApi apiServer = RetrofitService.getInstance().getApiService();
    private static volatile RequestWithViewUtils instance;
    private Context context;

    private RequestWithViewUtils() {
    }

    public static RequestWithViewUtils getInstance() {
        if (instance == null) {
            synchronized (Object.class) {
                if (instance == null) {
                    instance = new RequestWithViewUtils();
                }
            }
        }
        return instance;
    }

    private CompositeDisposable compositeDisposable;


    public void addDisposable(Observable<?> observable, BaseObserver observer) {
        if (compositeDisposable == null) {
            compositeDisposable = new CompositeDisposable();
        }
        compositeDisposable
                .add(observable.subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribeWith(observer));
    }

    private void removeDisposable() {
        if (compositeDisposable != null) {
            compositeDisposable.dispose();
        }
    }
    

}
